{extend name="../../../view/public/base" /}
{block name="css"}
<style>
    .select-test {
        position: absolute;
        max-height: 500px;
        height: 350px;
        overflow: auto;
        width: 100%;
        z-index: 123;
        display: none;
        border: 1px solid silver;
        top: 42px;
    }
    .layui-table img {
        max-width: 180px;
    }

    .layui-show {
        display: block !important;
    }

    .layui-form-pane .layui-form-label {
        font-size: 10px;
    }

    .layui-elip, .layui-form-checkbox span, .layui-form-pane .layui-form-label {
        text-overflow: clip;
        white-space: nowrap;
    }
</style>
<link rel="stylesheet" href="/layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
{/block}
{block name="body"}
<div class="bw-container">
    <div class="bw-main">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" style="height: 1100px">
                <div class="layui-card-header"><i class="fa fa-connectdevelop"></i>应用信息</div>
                <div class="layui-card-body">
                    <blockquote class="layui-elem-quote layui-text" style="border-left: 5px solid #01AAED;"
                                id="tab_change">
                        尊敬的【{$member_miniapp.appname}】合作伙伴您好,今天是{$date}日,欢迎使用【{$web_name}】SaaS平台的《{$miniapp.title}》应用。<br><br>
                        应用简介：{$miniapp.describe}
                    </blockquote>

                    <input type="hidden" id="id" name="id" value=""/>
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">关于应用</li>
                            <li>应用配置</li>
                            {if $miniapp['is_wechat_pay'] == 1}
                            <li>微信支付</li>
                            {/if}
                            {if $miniapp['is_alipay_pay'] == 1}
                            <li>支付宝支付</li>
                            {/if}
                        </ul>
                        <div class="layui-tab-content">
                            <!-- 关于应用-->
                            <div class="layui-tab-item layui-show">
                                <table class="layui-table ">
                                    <colgroup>
                                        <col width="180">
                                        <col width="120">
                                        <col>
                                    </colgroup>
                                    <tbody>
                                    <tr>
                                        <td rowspan="5"><img src="{$miniapp.logo_image}" height="180px" width="180px">
                                        </td>
                                        <td style="font-weight:bold">应用标识名</td>
                                        <td><span class="layui-badge layui-bg-blue">{$miniapp.title}</span></td>
                                    </tr>
                                    <tr>
                                        <td>应用类型：</td>
                                        <td>
                                            {if strpos($miniapp['types'], 'mini_program') !== false}<span
                                                class='layui-badge'>小程序</span> {/if}
                                            {if strpos($miniapp['types'], 'app') !== false}<span
                                                class='layui-badge'>app</span> {/if}
                                            {if strpos($miniapp['types'], 'h5') !== false}<span
                                                class='layui-badge'>h5</span> {/if}
                                            {if strpos($miniapp['types'], 'official') !== false}<span
                                                class='layui-badge'>公众号</span> {/if}
                                            {if strpos($miniapp['types'], 'system') !== false}<span class='layui-badge'>系统</span>
                                            {/if}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>服务方式：</td>
                                        <td><span class="layui-badge layui-bg-gray">
                                            {if $miniapp['is_openapp'] == 1}开放平台
                                            {else}独立应用
                                            {/if}
                                        </span></td>
                                    </tr>
                                    <tr>
                                        <td>更新时间：</td>
                                        <td>{$miniapp.update_time | date="Y-m-d H:i:s"}</td>
                                    </tr>
                                    <tr>
                                        <td>最新版本：</td>
                                        <td>v{$miniapp.version}</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="layui-card-header"><i class="fa fa-connectdevelop"></i>&nbsp我的应用</div>
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="100">
                                        <col width="200">
                                        <col width="200">
                                        <col>
                                        <col>
                                        <col>
                                        <col width="200">
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th>应用名称</th>
                                        <th>应用ID</th>
                                        <th>公众号APPID{if $member_miniapp.mp_open_auth }<span style="font-size:8px;color: green;margin-left: 2px">(已接入成功)</span>{/if}</th>
                                        <th>小程序APPID{if $member_miniapp.miniapp_open_auth and $is_authorize}<span style="font-size:8px;color: green;margin-left: 2px">(已接入成功)</span>{/if}</th></th>
                                        <th>客户端ID</th>
                                        <th>当前版本</th>
                                        <th>模板编号</th>
                                        <th>更新时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <td>{$member_miniapp.appname}</td>
                                        <td>{$member_miniapp_id}</td>
                                        <td>{$member_miniapp.mp_appid|default="未接入"}</td>
                                        <td>{$member_miniapp.miniapp_appid|default="未接入"}{if $update_var && $member_miniapp.miniapp_appid }<i onmouseover="showTips(this)" class="fa fa-cloud-upload" style="color: red;margin-left: 2px"></i>{/if}</td>
                                        <td>{$member_miniapp.service_id}</td>
                                        <td>{$member_miniapp.version}</td>
                                        <td>{$member_miniapp.template_id|default="0"}</td>
                                        <td>{$miniapp.update_time | date="Y-m-d H:i:s"}</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <!-- 小程序开放平台管理START-->
                                {if $member_miniapp->miniapp->is_openapp == 1 &&
                                (strpos($member_miniapp.miniapp.types,'mini_program') !== false)}
                                <div class="layui-card-header"><i class="fa fa-connectdevelop"></i>&nbsp小程序开放平台上架流程</div>
                                <div class="layui-tab layui-tab-card">
                                    <blockquote class="layui-elem-quote layui-text" style="border-left: 5px solid #ed7f01;">
                                        <ul>
                                            <li>小程序商城需要您在微信公众平台先申请自己的小程序，并且授权给商城使用。</li>
                                            <li>授权完成即可显示当前小程序商城的信息。有小程序的基础信息，也有小程序的版本信息。</li>
                                            <li>如果您还没有小程序，需要先去<a href="https://mp.weixin.qq.com/" target="_blank" class="ns-text-color">微信公众平台</a>申请下！申请完公众号后，直接授权给平台，即可拥有自己的小程序商城。
                                            </li>
                                        </ul>
                                    </blockquote>
                                    <ul class="layui-tab-title">
                                        <li class="{if $audit.is_commit == 1}layui-this{/if}">第一步、基础信息设置</li>

                                        <li class="{if $audit.is_commit == 2}layui-this{/if}">第二步、{$update_var ?
                                            '升级代码':'上传代码'}
                                        </li>
                                        <li class="{if $audit.is_commit == 3}layui-this{/if}">第三步、提交审核</li>
                                        <li class="{if $audit.is_commit == 4}layui-this{/if}">第四步、发布小程序</li>

                                    </ul>
                                    <div class="layui-tab-content" style="height: 100px;">
                                        <div class="layui-tab-item {if $audit.is_commit == 1}layui-show{/if}">
                                            <label class="layui-form-label">操作提示：</label>
                                            <div class="layui-input-block">
                                                {if $audit.is_commit != 3 && $audit.state == 0}
                                                    {if $member_miniapp.miniapp_open_auth == 1 }
                                                    <span style="font-size:8px;color: green;margin-left: 2px">(已授权设置成功)</span>
                                                    {else /}
                                                    <a href="{:sysuri('/manage/member/openAuth',['type'=>'mini_program','miniapp_id'=>$member_miniapp_id])}"
                                                       class="layui-btn layui-btn-xs" target="_blank">授权小程序</a>
                                                    {/if}

                                                {/if}
                                                {if $member_miniapp.miniapp_open_auth}
                                                <button type="button"
                                                        data-url="{:sysuri('/manage/member/setDomain',['miniapp_id'=>$member_miniapp_id])}"
                                                        class="layui-btn  layui-btn-xs" id="setDomain"><i
                                                        class="iconfont icon-lianjie"></i>绑定业务域名
                                                </button>
                                                {/if}
                                            </div>

                                        </div>


                                        <div class="layui-tab-item {if $audit.is_commit == 2}layui-show{/if}">
                                            <!-- 上传代码 -->
                                            <blockquote class="layui-elem-quote layui-text">
                                                温馨提示：如果您购买的小程序要一键上架程序，或者有新版本需要更新，此处可以进行提交代码，代码提交成功后，可以进行下一步的提交审核。
                                            </blockquote>
                                            <label class="layui-form-label">操作提示：</label>
                                            {if ($audit.is_commit == 2 || ($audit.is_commit == 3 && $audit.state == 0))
                                            && $member_miniapp.miniapp_open_auth}
                                            <div class="layui-input-block">
                                                <td>
                                                    <button type="button"
                                                            data-url="{:sysuri('/manage/member/upCode',['miniapp_id'=>$member_miniapp_id])}"
                                                            class="layui-btn layui-btn-xs" id="upCode"><i
                                                            class="iconfont icon-lianjie"></i>{$update_var?'立即升级':'上架程序'}
                                                    </button>
                                                </td>
                                            </div>
                                            {else /}
                                            <span style="color: red">此步骤没有需要完成的操作！</span>
                                            {/if}
                                        </div>
                                        <div class="layui-tab-item {if $audit.is_commit == 3}layui-show{/if}">
                                            <blockquote class="layui-elem-quote layui-text">
                                                温馨提示：请先上架程序或者升级程序后，再进行提交审核！；此处提交您购买的小程序最新版本号的代码给微信官网进行审核。
                                            </blockquote>
<!--                                            <a href="{:sysuri('/manage/member/submitAudit',['miniapp_id'=>$member_miniapp_id])}"-->
<!--                                               class="layui-btn layui-btn-xs" target="_self">提交审核</a>-->
                                            <button type="button"
                                                    data-url="{:sysuri('/manage/member/submitAudit',['miniapp_id'=>$member_miniapp_id])}"
                                                    class="layui-btn layui-btn-xs" id="submitAudit"><i
                                                    class="iconfont icon-lianjie"></i>提交审核
                                            </button>
                                            <button type="button"
                                                    data-url="{:sysuri('/manage/member/getAuditStatus',['miniapp_id'=>$member_miniapp_id])}"
                                                    class="layui-btn layui-btn-xs" id="getAuditStatus"><i
                                                    class="iconfont icon-lianjie"></i>查询审核状态
                                            </button>
                                            <button type="button"
                                                    data-url="{:sysuri('/manage/member/getQrCode',['miniapp_id'=>$member_miniapp_id])}"
                                                    class="layui-btn layui-btn-xs" id="getQrCode"><i
                                                    class="iconfont icon-lianjie"></i>获取小程序体验二维码
                                            </button>
                                            <button type="button"
                                                    data-url="{:sysuri('/manage/member/resetAudit',['miniapp_id'=>$member_miniapp_id])}"
                                                    class="layui-btn layui-btn-xs" id="resetAudit"><i
                                                    class="iconfont icon-lianjie"></i>强制撤销审核
                                            </button>

                                        </div>
                                        <div class="layui-tab-item {if $audit.is_commit == 4}layui-show{/if}">
                                            <label class="layui-form-label">操作提示：</label>
                                            <button type="button"
                                                    data-url="{:sysuri('/manage/member/publishCode',['miniapp_id'=>$member_miniapp_id])}"
                                                    class="layui-btn layui-btn-xs" id="publishCode"><i
                                                    class="iconfont icon-lianjie"></i>发布小程序
                                            </button>
                                        </div>

                                    </div>
                                </div>
                                {/if}
                                <!-- 小程序开放平台管理END-->
                            </div>

                            <!--应用配置-->
                            <div class="layui-tab-item">
                                <form class="layui-form layui-form-pane" id="form1" autocomplete="off">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"><span style="color:red;"></span>应用名称：</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="appname" lay-verify="appname" placeholder="请输入应用名称"
                                                   class="layui-input" value="{$member_miniapp.appname}">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label"><span style="color:red;"></span>微信服务商：</label>
                                        <div class="layui-input-block">
                                            <input type="radio" name="is_psp" lay-filter="is_psp" value="0"
                                                   title="独立商户号" {$member_miniapp.is_psp==0 ? 'checked':'' } >
<!--                                            <input type="radio" name="is_psp" lay-filter="is_psp" value="1"-->
<!--                                                   title="微信服务商" {$member_miniapp.is_psp==1 ? 'checked':'' }>-->
                                        </div>
                                    </div>

                                    <div class="layui-form-item" id="psp_appid" {if $member_miniapp[
                                    'is_psp'] == 0}style="display: none"{/if}>
                                    <label class="layui-form-label"><span
                                            style="color:red;"></span>服务商APPID：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="psp_appid" lay-verify="psp_appid"
                                               placeholder="请输入服务商APPID" class="layui-input"
                                               value="{$member_miniapp.psp_appid}">
                                    </div>
                            </div>

                            <!--小程序配置-->
                            {if strpos($miniapp['types'], 'mini_program') !== false}
                            <div>
                                <div class="layui-card-header"><i class="fa fa-wechat"></i>&nbsp小程序
                                    {if $miniapp['is_openapp'] == 1}
                                        {if $member_miniapp.miniapp_open_auth == 1 }
                                        <span style="font-size:8px;color: green;margin-left: 2px">(已接入成功)</span>
                                        <a href="{:sysuri('/manage/member/openAuth',['type'=>'mini_program','miniapp_id'=>$member_miniapp_id])}" class="layui-btn layui-btn-xs" target="_blank">重新授权</a>
                                        {else /}
                                        <a href="{:sysuri('/manage/member/openAuth',['type'=>'mini_program','miniapp_id'=>$member_miniapp_id])}" class="layui-btn layui-btn-xs" target="_blank">授权接入</a>
                                        {/if}
                                    {/if}
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span style="color:red;"></span>AppID：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="miniapp_appid" lay-verify="miniapp_appid"
                                               placeholder="请输入AppID(小程序)" class="layui-input"
                                               value="{$member_miniapp.miniapp_appid}">
                                    </div>
                                </div>

                                <!--独立应用需要AppSecret-->
                                {if $miniapp['is_openapp'] == 0}
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color: red; font-size: 20px"></span>AppSecret：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="miniapp_secret" id="miniapp_secret"
                                               lay-verify="live_number" placeholder="请输入AppSecret(小程序)"
                                               class="layui-input" value="{$member_miniapp.miniapp_secret}">
                                    </div>
                                </div>
                                {/if}

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span style="color:red;"></span>小程序状态颜色：</label>
                                    <div class="layui-input-inline">
                                        <div id="colornavbar_color" style="margin-left: 30px;"></div>
                                        <input type="hidden" name="navbar_color" id="inputnavbar_color"
                                               value="{$member_miniapp.navbar_color}">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color: red; font-size: 20px"></span>小程序文字样式：</label>
                                    <div class="layui-input-inline">
                                        <select name="navbar_style" id="navbar_style" lay-verify="required">
                                            {if !empty($member_miniapp.navbar_style)}
                                            <option value="#ffffff" {$member_miniapp.navbar_style=='#ffffff' ?
                                            'selected=""':'' } >白色</option>
                                            <option value="#000000" {$member_miniapp.navbar_style=='#000000' ?
                                            'selected=""':'' }>黑色</option>
                                            {else/}
                                            <option value="#ffffff" selected="">白色</option>
                                            <option value="#000000">黑色</option>
                                            {/if}
                                        </select>
                                    </div>
                                </div>
                            </div>
                            {/if}

                            <!--公众号配置-->
                            {if strpos($miniapp['types'], 'official') !== false}
                            <!--独立应用需要内容多,开放平台只需要AppID-->
                            {if $miniapp['is_openapp'] == 0}
                            <div>
                                <div class="layui-card-header"><i class="fa fa-cubes"></i>&nbsp公众号</div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">授权验证(URL)：</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" value="{$navbar_url}" readonly>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color:red;"></span>AppID：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mp_appid" id="mp_appid" lay-verify="mp_appid"
                                               placeholder="请输入AppID(公众号)" class="layui-input"
                                               value="{$member_miniapp.mp_appid}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">把授权验证(URL)中$APPID$替换为你填写的公众号AppID</div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color: red; font-size: 20px"></span>AppSecret：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mp_secret" id="mp_secret" lay-verify="mp_secret"
                                               placeholder="请输入AppSecret(公众号)" class="layui-input"
                                               value="{$member_miniapp.mp_secret}">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color: red; font-size: 20px"></span>Token：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mp_token" id="mp_token" lay-verify="mp_token"
                                               placeholder="请输入Token(公众号)" class="layui-input"
                                               value="{$member_miniapp.mp_token}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">Token必须为英文或数字，长度为3-32字符。如不填写则默认为“TOKEN”。</div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color: red; font-size: 20px"></span>EncodingAESKey：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mp_aes_key" id="mp_aes_key" lay-verify="mp_token"
                                               placeholder="请输入EncodingAESKey" class="layui-input"
                                               value="{$member_miniapp.mp_aes_key}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">公众号消息加密密钥由43位字符组成，可随机修改，字符范围为A-Z，a-z，0-9。</div>
                                </div>
                            </div>
                            {else /}
                            <div>
                                <div class="layui-card-header"><i class="fa fa-cubes"></i>&nbsp公众号
                                    {if $member_miniapp.mp_open_auth == 1 }
                                    <span style="font-size:8px;color: green;margin-left: 2px">(已接入成功)</span>
                                    <a href="{:sysuri('/manage/member/openAuth',['type'=>'official','miniapp_id'=>$member_miniapp_id])}" class="layui-btn layui-btn-xs" target="_blank">重新授权</a>
                                    {else /}
                                    <a href="{:sysuri('/manage/member/openAuth',['type'=>'official','miniapp_id'=>$member_miniapp_id])}" class="layui-btn layui-btn-xs" target="_blank">接入授权</a>
                                    {/if}
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color:red;"></span>AppID：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="mp_appid" id="mp_appid" lay-verify="mp_appid"
                                               placeholder="请输入AppID(公众号)" class="layui-input"
                                               value="{$member_miniapp.mp_appid}">
                                    </div>
                                </div>
                            </div>
                            {/if}
                            {/if}

                            <button type="button" class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit=""
                                    lay-filter="apply">修改
                            </button>
                            </form>
                        </div>

                        <!--微信支付-->
                        <div class="layui-tab-item">
                            <form class="layui-form layui-form-pane" id="form2" autocomplete="off">
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span
                                            style="color:red;"></span>商户号(mch_id)：</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="mch_id" placeholder="请输入商户号(mch_id)"
                                               class="layui-input" value="{$wechat.mch_id ?: ''}" lay-verify="required">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label"><span
                                                style="color: red; font-size: 20px"></span>API密钥：</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="key" id="key" placeholder="请输入API密钥"
                                                   class="layui-input" value="{$wechat.key ?: ''}"
                                                   lay-verify="required">
                                        </div>
                                    </div>
                                </div>


                                <div class="layui-form-item">
                                    <label class="layui-form-label">支付证书(.pem)</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input layui-input-inline" name="cert_path"
                                               value="{$wechat.cert_path ?: ''}" placeholder="请上传支付证书(pem格式)"
                                               style='width: 500px'>
                                        <div class="layui-upload">
                                            <button type="button" class="layui-btn layui-btn-normal" id="cert_path">
                                                上传证书
                                            </button>
                                            <div class="layui-upload-list" id="cert_pathPreview"
                                                 style="display: none;"></div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">证书秘钥(.pem)</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input layui-input-inline" name="key_path"
                                               value="{$wechat.key_path ?: ''}" placeholder="请上传证书秘钥(pem格式)"
                                               style='width: 500px'>
                                        <div class="layui-upload">
                                            <button type="button" class="layui-btn layui-btn-normal" id="key_path">
                                                上传证书秘钥
                                            </button>
                                            <div class="layui-upload-list" id="key_pathPreview"
                                                 style="display: none;"></div>
                                        </div>
                                    </div>
                                </div>

                                <button type="button" class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit=""
                                        lay-filter="wechat">修改
                                </button>
                            </form>
                        </div>

                        <!--支付宝支付-->
                        <div class="layui-tab-item">
                            <form class="layui-form layui-form-pane" id="form3" autocomplete="off">
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span style="color:red;"></span>支付应用ID：</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="app_id" placeholder="请输入支付应用ID" class="layui-input"
                                               value="{$alipay.app_id ?: ''}" lay-verify="required">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span style="color: red; font-size: 20px"></span>支付宝(证书)：</label>
                                    <div class="layui-input-block">
                                        <textarea name="public_key" placeholder="请输入支付宝(证书)" class="layui-textarea"
                                                  lay-verify="required">{$alipay.public_key ?: ''}</textarea>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span style="color: red; font-size: 20px"></span>支付宝(密钥)：</label>
                                    <div class="layui-input-block">
                                        <textarea name="private_key" placeholder="请输入支付宝(密钥)" class="layui-textarea"
                                                  lay-verify="required">{$alipay.private_key ?: ''}</textarea>
                                    </div>
                                </div>

                                <button type="button" class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit=""
                                        lay-filter="alipay">修改
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>


{/block}

{block name="js"}

<script>

    var form;
    var tab_type = '';
    var upload;
    layui.use(['form', 'util', 'element', 'colorpicker', 'upload', 'bwutil'], function () {
        var element = layui.element, colorpicker = layui.colorpicker,
            bwutil = layui.bwutil;
        form = layui.form;

        upload = layui.upload;
        bw_upload(upload, 'cert_path', 'file', 'cert_path',{
            upload_type:'local',
            domain:0
        });
        bw_upload(upload, 'key_path', 'file', 'key_path',{
            upload_type:'local',
            domain:0
        });

        //触发tab事件
        element.on('tab(docDemoTabBrief)', function (elem) {
            //TODO 将筛选条件全部清空
            /*document.getElementById("form1").reset();
            document.getElementById("form2").reset();*/

            //tab切换下标事件
            tab_type = getType(elem.index);
        });


        form.on('radio(is_psp)', function (data) {
            if (data.value == 1) $("#psp_appid").show();
            else $("#psp_appid").hide();
        });

        colorpicker.render({ //无初始色值时
            elem: '#colornavbar_color'
            , color: "{$member_miniapp.navbar_color ?: '#000'}" //默认值
            , done: function (color) {
                //选色回调
                $('#inputnavbar_color').val(color);
            }
        });

        form.on('submit(apply)', function (obj) {
            data = obj.field;
            data.id = {$member_miniapp.id};

            //ajax调用后台接口
            bwajax.post("{:Url('edit')}?miniapp_id={$member_miniapp_id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        });
        form.on('submit(wechat)', function (obj) {
            data = obj.field;

            //ajax调用后台接口
            bwajax.post("{:Url('wechat')}?miniapp_id={$member_miniapp_id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('修改成功', {icon: 1});
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        });
        form.on('submit(alipay)', function (obj) {
            data = obj.field;

            //ajax调用后台接口
            bwajax.post("{:Url('alipay')}?miniapp_id={$member_miniapp_id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('修改成功', {icon: 1});
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        });


        $('#setDomain').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm('确定修改授权域名吗？', '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.post(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            layer.msg(response.data.msg, {icon: 1},function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });
        $('#upCode').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm("要提交【v{$miniapp.version}】版本的代码吗？", '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.post(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            layer.msg(response.data.msg, {icon: 1},function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });
        //submitAudit
        $('#submitAudit').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.openFrame(url, "提交审核代码");
        });
        $('#getAuditStatus').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm('确定查询代码审核状态？', '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.get(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            layer.msg(response.data.msg, {icon: 1,time: 3000},function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });
        $('#getQrCode').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm('确定获取小程序体验二维码？', '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.get(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            //layer.msg(response.data.msg, {icon: 1});
                            bwutil.openFrame(response.data.data.data.qr_url,"扫码体验",460,500);
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });
        $('#resetAudit').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm('确定强制撤销审核？', '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.post(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            layer.msg(response.data.msg, {icon: 1});
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });
        $('#publishCode').on('click', function () {
            var othis = $(this), url = othis.data('url');
            bwutil.confirm('确定发布【v{$miniapp.version}】小程序？', '提示消息', '确定', function () {
                //ajax调用后台接口
                bwajax.post(url)
                    .then(function (response) {
                        if (response.data.data.errcode === 0) {
                            layer.msg(response.data.msg, {icon: 1},function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(response.data.msg, {icon: 2});
                        }
                    })
            }, '取消');
        });

    })


    function getIndex(type) {
        var rs = 0;
        switch (type) {
            case '':
                rs = 0;
                break;
            case 'apply':
                rs = 1;
                break;
            case 'wechat':
                rs = 2;
                break;
        }
        return rs;
    }

    function getType(index) {
        var rs = 'text';
        var msg = '';
        switch (index) {
            case 0:
                rs = '';
                msg += "应用描述:<br>\n" +
                    "                        尊敬的【{$member_miniapp.appname}】合作伙伴您好,今天是{$date}日,欢迎使用【{$web_name}】SaaS平台的《{$miniapp.title}》应用。<br>\n" +
                    "                        {$miniapp.describe}";
                break;
            case 1:
                rs = 'apply';
                msg += '友情提示：<br>\n' +
                    '1、如开启服务商支付,请确认绑定的授权公众号或小程序在微信官方商户号中授权服务商APPID权限。<br>\n' +
                    '\n' +
                    '2、应用客户端认证ID：';
                break;
            case 2:
                rs = 'wechat';
                msg += '友情提示：<br>\n' +
                    '1、您的微信支付证书和证书密钥是您的安全凭证,平台承诺不做任何其它用途,但任何应用不是绝对安全,若出现证书被黑客非法使用造成损失的,平台将不承担任何损失,所以请谨慎上传您的支付证书和证书密钥。';
                break;
            case 3:
                rs = 'alipay';
                msg += '友情提示：<br>\n' +
                    '1、您的支付宝支付证书和证书密钥是您的安全凭证,平台承诺不做任何其它用途,但任何应用不是绝对安全,若出现证书被黑客非法使用造成损失的,平台将不承担任何损失,所以请谨慎上传您的支付证书和证书密钥。';
                break;

        }
        $('#tab_change').html(msg);
        return rs;
    }
    function showTips(obj) {
        layer.tips("小程序有可用升级啦",
            obj,
            {tips:[2, '#663ff'], time:3000});
    }


</script>
{/block}